package work.huangxin.share.controller.classSchedule;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import work.huangxin.share.domain.other.ArticleMessage;
import work.huangxin.share.domain.schedule.CampusInfo;
import work.huangxin.share.domain.schedule.CampusInfoVo;
import work.huangxin.share.service.CampusInfoService;
import work.huangxin.share.service.impl.ArticleOperationService;
import work.huangxin.share.service.impl.UserMessageOperationService;
import work.huangxin.share.util.status.BaseResponse;
import work.huangxin.share.util.status.ResponseData;

import java.util.List;

/**
 * @author 季台星
 * @Date 2023 04 26 12 53
 */
@RestController
@RequestMapping("/wx/campus")
public class CampusInfoController {
    @Autowired
    private CampusInfoService campusInfoService;
    @Autowired
    private UserMessageOperationService userMessageOperationService;

    @Autowired
    private ArticleOperationService articleOperationService;
    @GetMapping("/list")
    public BaseResponse getCampusInfo(){
        List<CampusInfo> campusInfoList = campusInfoService.getCampusInfoList();
        return ResponseData.success(campusInfoList);
    }
    @GetMapping("/get/{campus}")
    public BaseResponse getCampusById(@PathVariable("campus") Long campusId){
        CampusInfo campusInfoById = campusInfoService.getCampusInfoById(campusId);
        CampusInfoVo campusInfoVo = new CampusInfoVo();
        BeanUtils.copyProperties(campusInfoById,campusInfoVo,"totalUser","totalArticle");
        campusInfoVo.setTotalUser(userMessageOperationService.getTotalUser());
        campusInfoVo.setTotalArticle(articleOperationService.getTotalArticle());
        return ResponseData.success(campusInfoVo);
    }
    @GetMapping("/search")
    public BaseResponse searchCampus(@RequestParam Integer pageNo,
                                     @RequestParam Integer pageSize,
                                     @RequestParam String keyword){
        PageInfo<CampusInfo> campusInfoList = campusInfoService.searchCampusInfoByKeyWord(pageNo,pageSize,keyword);
        return ResponseData.success(campusInfoList);
    }
}
